home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!devmaccn.demon.co.uk
- From: Alan Griffiths <aGriffiths@ma.ccngroup.com>
- Newsgroups: comp.lang.c++
- Subject: Re: STL and namespaces?
- Date: Fri, 29 Mar 1996 15:26:16 GMT
- Organization: CCN Market Analysis
- Distribution: world
- Message-ID: <85140771wnr@ma.ccngroup.com>
- References: <314F1A4C.2868@ix.netcom.con>
- Reply-To: aGriffiths@ma.ccngroup.com
- X-NNTP-Posting-Host: devmaccn.demon.co.uk
- X-Broken-Date: Friday, Mar 29, 1996 15.26.16 GMT
- X-Newsreader: Newswin Alpha 0.6
- X-Mail2News-Path: devmaccn.demon.co.uk
-
- In article: <314F1A4C.2868@ix.netcom.con> Robert Kleemann <goose@ix.netcom.con> writes:
- >
- > I've been using The HP STL (Dec95 version) with the Microsoft VC4
- > Compiler for the past few months and have taken Microsoft's
- > recommendation to stick all the STL include files in its own namespace
- > to avoid global operator conflicts with Microsoft's class library (MFC).
- > The name std is recommend by ANSI for the standard template library
- > namespace.
- >
- > After tweaking some of the STL files this has worked pretty well except
- > for the following problems:
- >
- > 1) global operators cannot be accessed without the namespace prefix eg:
- > std::string s1;
- > std::string s2;
- > if (s1==s2) // this doesn't work
- > ;
- > if (std::operator==(s1,s2)) // this does work
- > ;
-
- using namespace std;
- string s1;
- string s2;
- if (s1 == s2)
-
- > 2) STL algorithms that use global operators don't work on classes that
- > define these operators eg:
- >
- > class C
- > {
- > C();
- > C(const C& c);
- > C& operator=(const C& c);
- > friend bool operator==(const C& c1, const C& c2);
- > };
- > inline bool operator==(const C& c1, const C& c2)
- > {
- > return true;
- > }
- namespace std
- {
- inline bool operator==(const C& c1, const C& c2)
- {
- return true;
- }
- }
- > void main()
- > {
- > std::list<C> container;
- > std::list<C>::iterator i;
- > // the following line will not compile because
- > // find require operator== to be defined for C
- > i = std::find( container.begin(), container.end(),
- > C() );
- > }
- >
- > The first problem is expected and and although it makes the code less
- > readable, it is not a major problem. The second problem has no clear
- > workaround and makes me want to stop using namespaces.
- >
- > My question is: are other people out there using STL with namespaces?
- > Have you run into these problems? Have you found better workarounds?
-
- Avoid the MSVC4 compiler - problem (2) is a defect in the MS
- implementation of namespaces! ;)
-
- > Can I expect these namespace problems to be fixed in future STL
- > implementations or would I be better off including STL in global space
- > and instead try sticking MFC in a namespace.
-
- You may hope that the problem will be fixed in a future MSVC
- implementation.
-
- Alan Griffiths | Also editor of: The ISDF Newsletter
- Senior Systems Consultant, | (An Association of C and C++ Users publication)
- CCN Group Limited. | (ISDF editor : isdf@octopull.demon.co.uk)
- (agriffiths@ma.ccngroup.com) | (For ACCU see : http://bach.cis.temple.edu/accu)
-
-